<?php

namespace App\Admin\Actions\Apply;

use App\Models\Apply;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class Check extends RowAction
{
    public $name = '审核';

    public function handle(Model $model, Request $request)
    {
        // $model ...
        $data = [
            'status' => $request->input('op_status'),
            'remark' => $request->input('remark')
        ];
        if(!Apply::where('id', $model->getKey())->update($data)) {
            return $this->response()->error('操作失败');
        }
        return $this->response()->success('操作成功')->refresh();
    }

    public function form(Model $model) {
        $this->radio('op_status', '状态')->options(Apply::$_status)->default($model->status);
        $this->textarea('remark', '备注')->value($model->remark);
    }

}
